program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  fin, fout: textfile;
  n, i, j, a, b, colour, flag: integer;
  col: array of integer;
begin
  assignfile(fin, 'input.txt');
  reset(fin);
  assignfile(fout, 'output.txt');
  rewrite(fout);
  readln(fin, n);
  setlength(col, n);
  for i:=0 to n-1 do
    col[i]:=i;
  for i:=0 to n-1 do
  begin
    readln(fin, a, b);
    if (col[a-1]<>col[b-1]) then
    begin
      colour:=col[a-1];
      for j:=0 to n-1 do
        if (col[j]=colour) then
          col[j]:=col[b-1];
    end;
  end;
  for i:=0 to n-1 do            
  begin
    flag:=0;
    for j:=0 to n-1 do
    begin
      if (i=col[j]) then
      begin
        write(fout, j+1, ' ');
        col[j]:=-1;
        flag:=1;
      end;
    end;
    if (flag=1) then
      writeln(fout);
  end;
  closefile(fin);
  closefile(fout);
end.
